package core;

import core.genetic.crossover.*;
import core.genetic.mutation.*;
import core.genetic.mutation.single.*;
import core.genetic.selection.*;
import core.neural.IndividualBrain;
import core.sim.*;
import core.sim.aproxfunc.*;
import core.sim.elfarol.*;
import core.sim.ring.*;
import core.swarm.*;

public class Mode {

	public static Mode mode;
	
	
	final private  double mutRatePop;
	final private  double mutRateInd;
	
	final public  Crossover crossover;
	final public  SingleGeneMutation singleMutation;
	final public  HromozomMutation mutation;
	final public  Selection selection;
	final public  Evaluation evaluation;
	final public  SingleSimulation simulation;

	final public  int teamNb; 
	

	final public  int nbGenerations;

	final public  int popSize;
	final public  int geneSize;
	
	final public  double elitismRate;
	
	public int currentGeneration;
	
	final public  IndividualBrain brain;	
	
//	static {
//		mode = new Mode(1);		
//	}
	
	final public  int FEROMONS;
	final public  int MEMORY;

	final public String explanation;
	
	
	final public int type;
	
	
	public Mode(int type) {
		this.type = type; 
		mode = this;
		FEROMONS = 0;
		MEMORY = 0;
		simulation = new NeuralFunctionApproximation(51);
		teamNb = 1;
		nbGenerations = 10000;				
		elitismRate=0.031;
		currentGeneration = 0;
		evaluation = new RoundsAndSelfEvaluation(0, 1);
		
		
		switch (type) {
		
		
		
		case 1: // Rulet - DPC
			popSize = 100;
			mutRatePop = 0.6;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new DoublePointCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RouletteWheelSelection(0.4);

			explanation = "Type 1_(30,30,30), 100 npop, RouletteSel(0.4), NM(0.6,0.004), DPC"; 
			
			break;
		
		
		case 2: // Random - no crossover 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RandomSelection(0.4);

			explanation = "Type 2_(30,30,30), 100 npop, RandomSel(0.4), NM(0.95,0.004), NoC";

			break;
		
		case 3: // Rulet - no crossover
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RouletteWheelSelection(0.4);

			explanation = "Type 3_(30,30,30), 100 npop, RouletteSel(0.4), NM(0.95,0.004), NoC";

			break;


		case 4: // Random - LC
			popSize = 100;
			mutRatePop = 0.6;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new LearningCrossover(20, 0.2);
			singleMutation = new RandomMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RandomSelection(0.4);

			explanation = "Type 4: (30,30,30), 100 npop, RandSel(0.4), NM(0.6,0.004), LC(20,0.2)";

			break;	


			
		case 5: // Rulet - LC
			popSize = 100;
			mutRatePop = 0.6;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new LearningCrossover(20, 0.2);
			singleMutation = new RandomMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RouletteWheelSelection(0.4);

			explanation = "Type 5_(30,30,30), 100 npop, RouletteSel(0.4), NM(0.6,0.004), LC(20,0.2)";

			break;	
			


		case 6: // Swarm 4, 0 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(4 , 0);					

			explanation = "Type 6_(30,30,30), 100 npop, SwarmSel(4,0)";
			
			break;

			
		case 7: // Swarm 4, 4 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(4 , 4);					

			explanation = "Type 7_(30,30,30), 100 npop, SwarmSel(4,4)";
			
			break;


		case 8: // Swarm adv 4 - 4
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,4,4,20,0.2);

			explanation = "Type 8_(30,30,30), 100 npop, SwarmAdvSel(4,4,4,20,0.2)";
			
			break;
			

		case 9: // Swarm adv 20
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,0,20,20,0.2);

			explanation = "Type 9_(30,30,30), 100 npop, SwarmAdvSel(4,0,20,20,0.2)";
			
			break;
			

		case 10: // Swarm adv 50
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,0,50,20,0.2);

			explanation = "Type 10_(30,30,30), 100 npop, SwarmAdvSel(4,0,50,20,0.2)";
			
			break;
			

		case 11: // Swarm 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(2 , 0);	

			explanation = "Type 11_(30,30,30), 100 npop, SwarmSel(2,0)";
			
			break;
			

		case 12: // Swarm 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(10 , 0);	

			explanation = "Type 12_(30,30,30), 100 npop, SwarmSel(10,0)";
			
			break;
			
		case 13: // Swarm adv 20 - 4
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.004;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 30, 30, 30 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,0,20,20,0.2);

			explanation = "Type 13_(30,30,30), 100 npop, SwarmAdvSel(4,0,20,20,0.2)";
			
			break;
			

			
			
			
			
			
		case 101: // Rulet - DPC
			popSize = 100;
			mutRatePop = 0.6;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new DoublePointCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RouletteWheelSelection(0.4);

			explanation = "Type 101_(100), 100 npop, RouletteSel(0.4), NM(0.6,0.004), DPC"; 
			
			break;
		
		
		case 102: // Random - no crossover 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RandomSelection(0.4);

			explanation = "Type 102_(100), 100 npop, RandomSel(0.4), NM(0.95,0.004), NoC";

			break;
		
		case 103: // Rulet - no crossover
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RouletteWheelSelection(0.4);

			explanation = "Type 103_(100), 100 npop, RouletteSel(0.4), NM(0.95,0.004), NoC";

			break;


		case 104: // Random - LC
			popSize = 100;
			mutRatePop = 0.6;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new LearningCrossover(20, 0.2);
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RandomSelection(0.4);

			explanation = "Type 104: (100), 100 npop, RandSel(0.4), NM(0.6,0.004), LC(20,0.2)";

			break;	


			
		case 105: // Rulet - LC
			popSize = 100;
			mutRatePop = 0.6;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new LearningCrossover(20, 0.2);
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new RouletteWheelSelection(0.4);

			explanation = "Type 105_(100), 100 npop, RouletteSel(0.4), NM(0.6,0.004), LC(20,0.2)";

			break;	
			


		case 106: // Swarm 4, 0 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(4 , 0);					

			explanation = "Type 106_(100), 100 npop, SwarmSel(4,0)";
			
			break;

			
		case 107: // Swarm 4, 4 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(4 , 4);					

			explanation = "Type 107_(100), 100 npop, SwarmSel(4,4)";
			
			break;


		case 108: // Swarm adv
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,4,4,20,0.2);

			explanation = "Type 108_(100), 100 npop, SwarmAdvSel(4,4,4,20,0.2)";
			
			break;
			

		case 109: // Swarm adv
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,0,20,20,0.2);

			explanation = "Type 109_(100), 100 npop, SwarmAdvSel(4,0,20,20,0.2)";
			
			break;
			

		case 110: // Swarm adv
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,0,50,20,0.2);

			explanation = "Type 110_(100), 100 npop, SwarmAdvSel(4,0,50,20,0.2)";
			
			break;
			

		case 111: // Swarm 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(2 , 0);	

			explanation = "Type 111_(100), 100 npop, SwarmSel(2,0)";
			
			break;
			

		case 112: // Swarm 
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmSelection(10 , 0);	

			explanation = "Type 112_(100), 100 npop, SwarmSel(10,0)";
			
			break;
			
		case 113: // Swarm adv 20 - 4
			popSize = 100;
			mutRatePop = 0.95;
			mutRateInd = 0.02;
			brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[] { 100 });

			crossover = new NoCrossover();
			singleMutation = new NormalMutation();
			mutation = new AllGenesMutation(mutRatePop, mutRateInd);
			selection = new SwarmAdvSelection(4,0,20,20,0.2);

			explanation = "Type 113_(100), 100 npop, SwarmAdvSel(4,0,20,20,0.2)";
			
			break;	


		default:
			throw new RuntimeException("wrong case exception");
		}					
	
		geneSize = brain.LENGTH;		
	}
	
//	public Mode() {
//		mode = this;
//		FEROMONS = 0;
//		MEMORY = 0;
//		simulation = new FunctionOptimization();
//		brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[]{});
//		
//		teamNb = 1; 	
//		evaluation = new RoundsAndSelfEvaluation(0,1);
//
//		popSize = 100;
//		geneSize = brain.LENGTH;
//		nbGenerations = 10000;		
//		elitismRate=0.051;
//		currentGeneration = 0;
//			
//		mutRatePop = 0.3;
//		mutRateInd = 0.2;
//		
//		crossover = new UniformCrossover();//LearningCrossover(20, 0.2);
//		singleMutation = new RandomMutation();
//		mutation = new AllGenesMutation(mutRatePop, mutRateInd);
//		selection = new RouletteWheelSelection(0.4);//
//		
//		explanation = "Function optimization : 100 npop, RouletteSel(0.4), NM(0.6,0.2), UNC";
//	}
	
	
//	public Mode() {
//		mode = this;
//		FEROMONS = 3;
//		MEMORY = 3;
//		simulation = new RingWorldAdvSim();//NeuralFunctionApproximation(51);//AdvancedSparseSim(5, false);
//		brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[]{60});
//		
//		teamNb = 20; 	
//		evaluation = new RoundsAndSelfEvaluation(0,1);
//
//		popSize = 40;
//		geneSize = brain.LENGTH;
//		nbGenerations = 50;		
//		elitismRate=0.05;
//		currentGeneration = 0;
//			
//		mutRatePop = 0.6;
//		mutRateInd = 0.002;
//		
//		crossover = new LearningCrossover(20, 0.2);
//		singleMutation = new NormalMutation();
//		mutation = new AllGenesMutation(mutRatePop, mutRateInd);
//		selection = new SwarmSelection(2,1);//RouletteWheelSelection(0.4);//
//		explanation ="";
//	}
//	
//	public Mode() {
//		mode = this;
//		FEROMONS = 0;
//		MEMORY = 0;
//		simulation = new NeuralFunctionApproximation(51);//AdvancedSparseSim(5, false);
//		brain = new IndividualBrain(simulation, FEROMONS, MEMORY, new int[]{100});
//		
//		teamNb = 1; 	
//		evaluation = new RoundsAndSelfEvaluation(0,1);
//
//		popSize = 100;
//		geneSize = brain.LENGTH;
//		nbGenerations = 4000;		
//		elitismRate=0.03;
//		currentGeneration = 0;
//			
//		mutRatePop = 0.5;
//		mutRateInd = 0.04;
//		
//		crossover = new LearningCrossover(20, 0.2);
//		singleMutation = new NormalMutation();
//		mutation = new AllGenesMutation(mutRatePop, mutRateInd);
//		selection = new RouletteWheelSelection(0.4);//SwarmAdvSelection(8,4, 4, 20 , 0.2);//
//		
//		explanation = "Function Approx -- Neural(100), 100 npop, RouletteSim(0.4), NM(0.5,0.04), LC(20,0.2)";
//	}
	
}
